<?php
	defined('_JEXEC') or die('Restricted access');
    require_once(CUTEENGINE_BASE_FIELD_PATH."base_field_class.php");
	//
	// t_base_part
	//
	
	//abstract class t_base_part
	abstract class t_base_part implements i_base_part
	{
        // property declaration
		// private
        // A
		private $actions_for_fields_uses_as_included_in_list = '';
		// F
        private $fields_uses_as_included_in_list = '';
		
		// property declaration
		// protected 
        //  L
		protected $last_field_index = -1;
        // F
        protected $fields = array();
		protected $fields_positions = array();
        protected $first_index_always_last_position_field = -1;
        // P
		protected $part_enabled = false;
        protected $part_id = null;
        protected $part_name = null;
        protected $part_order = -1;
        protected $parent_part_name = null;
        protected $part_type = null;
        // R
        protected $required_actions = array();
        // S
        protected $specific_parameters = array();
		// property declaration
		// public
		// C
		const common_parameters_position_name = 1;
		const common_parameters_position_events = 2;
        const common_parameters_position_parent_part = 3;
		const common_parameters_position_last = 4;     
		// E
		public $executor_field = null;
        // M        
        public $main_tag = null;
        // P
        public $parent_component = null;
		public $created = false;
		// T
		public $tag_for_more_fields = null;
        // method declaration
		// protected
        // A
        protected function add_required_action($a_action_str,$a_action_index)
		{
            //echo "a_action_index:$a_action_index - a_action_str:$a_action_str<br>";
            $local_action = t_base_action::create_action_from_string($this->parent_component,$this,$a_action_str);
            $this->required_actions[$a_action_index] = $local_action;    
		}        
        // G
		abstract protected function generate_events_actions($a_events_array);
        abstract protected function get_child_action_of_parent_part();
        abstract protected function get_events_array();
		abstract protected function get_events_position_last();
        abstract protected function get_fields_position_last();
        abstract protected function get_parent_action_name();
        abstract protected function get_required_actions_position_last();
		abstract protected function get_specific_parameters_position_last();
        
        // method declaration
		// private      
        // G
        private function generate_fields_array($a_fields_string,$a_uses_as_included_in)
        {
           // echo "a_fields_string: $a_fields_string<br>";
	
			$a_fields_string = str_replace('\;', '__CE_SEMICOLON__',$a_fields_string);
			$local_array = explode(';',str_replace("|t_field_", "|;|t_field_", $a_fields_string));
            foreach($local_array as $local_field_item)
            {
                $local_field_item = str_replace('__CE_SEMICOLON__', ';',$local_field_item);
                if ((trim($local_field_item) != '')&&(trim($local_field_item) != '|'))
				{
                   // echo "local_field_item: $local_field_item - a_uses_as_included_in: $a_uses_as_included_in<br>";

					$local_field = $this->add_field_from_string($local_field_item); 
					$local_field->uses_as_included_in = $a_uses_as_included_in;
				}
            }
            
        }
		// method declaration
		// public        
		public function __construct($a_parent_component,$a_part_id,$a_part_order,
			$a_part_type,$a_part_common_parameters,$a_part_specific_parameters,
			$a_specific_fields_string,$a_required_actions_string,$a_part_enabled) 
		{
            //echo "1111111111111111111111111<br>";
			global $g_strings_utility_namespace;
			// echo __METHOD__.":  $a_part_id,$a_part_order,$a_part_type,$a_part_name,
				//$a_part_enabled<br>";
            $this->parent_component = $a_parent_component;
            $this->part_id = $a_part_id;
            $this->part_order = $a_part_order;
            $this->part_type = $a_part_type;
            $this->part_enabled = $a_part_enabled;
			// common_parameters
			$local_common_parameters = $g_strings_utility_namespace->check_string_parameters(
				$this,"",t_query_parameter::separator_level_0,$a_part_common_parameters,
				self::common_parameters_position_last,'COMMON PARAMETERS');
			$this->part_name = $local_common_parameters[self::common_parameters_position_name];
			$local_events_str = $local_common_parameters[self::common_parameters_position_events];
            $this->parent_part_name = $local_common_parameters[self::common_parameters_position_parent_part];
			//echo "this->part_name:".$this->part_name."<br>";
			// specific_parameters
			//echo "a_part_specific_parameters: $a_part_specific_parameters<br>";
			$this->specific_parameters = $g_strings_utility_namespace->check_string_parameters(
				$this,$this->part_name,t_query_parameter::separator_level_0,$a_part_specific_parameters,
				$this->get_specific_parameters_position_last(),'SPECIFIC PARAMETERS');
				
			// fields
			//echo "a_part_specific_parameters: $a_part_specific_parameters<br>";
			//echo "a_specific_fields_string: $a_specific_fields_string<br>";
			$local_fields_array = $g_strings_utility_namespace->check_string_parameters(
				$this,$this->part_name,t_query_parameter::separator_level_0,$a_specific_fields_string,
				$this->get_fields_position_last(),'FIELDS',true);			
            $this->import_fields_array_from_string(
				str_replace(t_query_parameter::separator_level_0, '', $a_specific_fields_string),false);
            $this->import_fields_array_from_string($this->fields_uses_as_included_in_list,true); 
			
            // required_actions
            //echo $a_required_actions_string;
			$local_actions_array = $g_strings_utility_namespace->check_string_parameters(
				$this,$this->part_name,t_query_parameter::separator_level_0,$a_required_actions_string,
				$this->get_required_actions_position_last(),'REQUIRED ACTIONS');
				
			//
            foreach($local_actions_array as $local_action_index => $local_action) 
            {
                //echo $local_action;
				
                if ($local_action != '')
				{
					//echo "local_action: $local_action<br>";
					$this->add_required_action($local_action, $local_action_index);
				}	
            }
			//echo "this->actions_for_fields_uses_as_included_in_list: '[".str_replace("'", "\'", $this->actions_for_fields_uses_as_included_in_list)."]'<br>";
			$local_string = $this->actions_for_fields_uses_as_included_in_list;
     
            $local_actions_array = explode(t_strings_utility_namespace::separator_level_0,$local_string);
           // echo "count(local_actions_array): ".count($local_actions_array)."<br>";
			foreach($local_actions_array as $local_action_index => $local_action) 
            {
                //echo $local_action;
				
                if ($local_action != '')
				{
					//echo "local_action: $local_action<br>";
					$this->add_required_action($local_action, $local_action_index);
				}	
            }
            // events
            //echo "local_events_str:$local_events_str<br>";
			$local_events_array = $g_strings_utility_namespace->check_string_parameters(
				$this,$this->part_name,t_query_parameter::separator_level_1,$local_events_str,
				$this->get_events_position_last(),'EVENTS');
			$local_events = $this->get_events_array();
            if (count($local_events_array) <> count($local_events))
            {
                throw new Exception('Error creating object class '.get_class($a_obj).
					" named: \"".$this->part_name."\". Events array count an event numer wrong (".
                    (count($local_events)) . ' instead of '.
                    ($this->get_events_position_last()-1).').');	
            }
            $this->generate_events_actions($local_events_array);
            // PARENT PART
            if ($this->has_parent_part())
            {
                //echo "this->part_name: ".$this->part_name." - this->parent_part_name: ".$this->parent_part_name."<br>";
                $local_parent_part = $this->parent_component->parts[$this->parent_part_name];
                if (isset($local_parent_part))
                {
                    $local_parent_action_name = $local_parent_part->get_parent_action_name();
                    $local_child_action = $this->get_child_action_of_parent_part();
					//print_r($local_child_action);
                    //echo "local_parent_action_name: ".$local_parent_action_name." <br> local_child_action->get_action_name : ".$local_child_action->get_action_name()."<br>";
					if (isset($local_child_action))
                    {
                        $local_child_action->set_main_action($local_parent_action_name);
                    }
                }
                else
                {
                    throw new Exception('Error creating class "'.get_class($this).
                        '" named: "'.$this->part_name.'". Parent part:"'.$this->parent_part_name.'" not found.');
                }
            }
			$this->created = true;
            
		}
		//A
        public function add_action_for_field_uses_as_included($a_string)
        {
            if ($this->created)
			{
				
				$this->add_required_action($a_string,count($this->required_actions));
			}
			else
			{
				//echo "a_string: $a_string<br>";
				if ($this->actions_for_fields_uses_as_included_in_list == '')
					$this->actions_for_fields_uses_as_included_in_list = $a_string;
				else
					$this->actions_for_fields_uses_as_included_in_list .= t_strings_utility_namespace::separator_level_0 . $a_string;
			}
        }
		
        public function add_field_uses_as_included($a_string)
        {
            $this->fields_uses_as_included_in_list = substr($this->fields_uses_as_included_in_list,0,-1) . $a_string;
			//echo "this->fields_uses_as_included_in_list: $this->fields_uses_as_included_in_list<br>";
        }
        public function add_event($a_field_event_type_index,$a_parent_required_action_index,$a_field_index)
        {
            //echo __METHOD__;
			//echo "a_field_event_type_index: $a_field_event_type_index<br>";
			$local_events = $this->get_events_array();
			$local_field_event_type = $local_events[$a_field_event_type_index];
            $local_field = $this->fields[$this->fields_positions[$a_field_index]];
            $local_action = $this->required_actions[$a_parent_required_action_index];
			// parent component
			$local_parent_component = $this->parent_component;
			if(method_exists($local_parent_component,'get_json_condition_values'))
				$local_json_condition_values = $local_parent_component->get_json_condition_values();
			else
				$local_json_condition_values = "[]";
			if(method_exists($local_parent_component,'get_json_condition_fileds'))
				$local_json_condition_fileds = $local_parent_component->get_json_condition_fileds();
			else
				$local_json_condition_fileds = "[]";
			$local_fields_list = "[]";//$this->get_json_db_fields_list();	
			//echo "local_fields_list: $local_fields_list<br>";
			//	
			$local_prefix_event_name = get_class($local_field); //$this->part_name;
            switch ($local_field_event_type) 
            {
	
                /*********** t_base_field::field_event_type_on_selected ***********/
                case t_base_field::field_event_type_on_selected:
                    $this->add_required_action('["'.$local_action->get_action_name().'","t_action_set_event_part","'.$this->get_action_name_of_part_event($local_field_event_type,"t_action_set_event_part").'",['.
                        '"'.$local_field->name.'"],"'.$local_field_event_type.'","'.$local_prefix_event_name.'_on_select"]',
                        (($this->get_required_actions_position_last()-1) + $a_field_event_type_index));
                break;
                /*********** t_base_field::field_event_type_on_edit ***********/
                case t_base_field::field_event_type_on_edit:
                    $this->add_required_action('["'.$local_action->get_action_name().'","t_action_set_event_part","'.$this->get_action_name_of_part_event($local_field_event_type,"t_action_set_event_part").'",['.
                        '"'.$local_field->name.'"],"'.$local_field_event_type.'","'.$local_prefix_event_name.'_on_edit"]',
                        (($this->get_required_actions_position_last()-1) + $a_field_event_type_index));
                break;
                /*********** t_base_field::field_event_type_on_cancel ***********/
                case t_base_field::field_event_type_on_cancel:
                    $this->add_required_action('["'.$local_action->get_action_name().'","t_action_set_event_part","'.$this->get_action_name_of_part_event($local_field_event_type,"t_action_set_event_part").'",['.
                        '"'.$local_field->name.'"],"'.$local_field_event_type.'","'.$local_prefix_event_name.'_on_cancel"]',
                        (($this->get_required_actions_position_last()-1) + $a_field_event_type_index));                
                break;
                /*********** t_base_field::field_event_type_on_save ***********/
                case t_base_field::field_event_type_on_save:
                    $this->add_required_action('["'.$local_action->get_action_name().'","t_action_set_event_part","'.$this->get_action_name_of_part_event($local_field_event_type,"t_action_set_event_part").'",['.
                        '"'.$local_field->name.'"],"'.$local_field_event_type.'","'.$local_prefix_event_name.'_on_save"]',
                        (($this->get_required_actions_position_last()-1) + $a_field_event_type_index));
                    $this->add_required_action('["'.$this->get_action_name_of_part_event($local_field_event_type,"t_action_set_event_part").'","t_action_set_values_into_db","'.$this->get_action_name_of_part_event($local_field_event_type,"t_action_set_values_into_db").'",['.
                        '"'.$local_field->name.'","'.$local_field->name.'","'.$local_field->name.'",""],"",'.$local_fields_list.','.$local_json_condition_fileds.','.$local_json_condition_values.',"false"]',
                        (($this->get_required_actions_position_last()-1) + $a_field_event_type_index));
                break;  
				/*********** t_base_field::field_event_type_on_insert ***********/
                case t_base_field::field_event_type_on_insert:
                    $this->add_required_action('["'.$local_action->get_action_name().'","t_action_set_event_part","'.$this->get_action_name_of_part_event($local_field_event_type,"t_action_set_event_part").'",['.
                        '"'.$local_field->name.'"],"'.$local_field_event_type.'","'.$local_prefix_event_name.'_on_insert"]',
                        (($this->get_required_actions_position_last()-1) + $a_field_event_type_index));
                break;				
				/*********** t_base_field::field_event_type_on_reload ***********/
                case t_base_field::field_event_type_on_reload:
                    $this->add_required_action('["'.$local_action->get_action_name().'","t_action_set_event_part","'.$this->get_action_name_of_part_event($local_field_event_type,"t_action_set_event_part").'",['.
                        '"'.$local_field->name.'"],"'.$local_field_event_type.'","'.$local_prefix_event_name.'_on_reload"]',
                        (($this->get_required_actions_position_last()-1) + $a_field_event_type_index));
                break;                
				/*********** t_base_field::field_event_type_on_delete ***********/
                case t_base_field::field_event_type_on_delete:
                    $this->add_required_action('["'.$local_action->get_action_name().'","t_action_set_event_part","'.$this->get_action_name_of_part_event($local_field_event_type,"t_action_set_event_part").'",['.
                        '"'.$local_field->name.'"],"'.$local_field_event_type.'","'.$local_prefix_event_name.'_on_delete"]',
                        (($this->get_required_actions_position_last()-1) + $a_field_event_type_index));
                    $this->add_required_action('["'.$this->get_action_name_of_part_event($local_field_event_type,"t_action_set_event_part").'","t_action_set_values_into_db","'.$this->get_action_name_of_part_event($local_field_event_type,"t_action_set_values_into_db").'",['.
                        '"'.$local_field->name.'","'.$local_field->name.'","'.$local_field->name.'",""],"",'.$local_fields_list.','.$local_json_condition_fileds.','.$local_json_condition_values.',"false"]',
                        (($this->get_required_actions_position_last()-1) + $a_field_event_type_index));                        
                break;
				/*********** t_base_field::field_event_type_on_paging ***********/
                case t_base_field::field_event_type_on_paging:
                    $this->add_required_action('["'.$local_action->get_action_name().'","t_action_set_event_part","'.$this->get_action_name_of_part_event($local_field_event_type,"t_action_set_event_part").'",['.
                        '"'.$local_field->name.'"],"'.$local_field_event_type.'","'.$local_prefix_event_name.'_on_paging"]',
                        (($this->get_required_actions_position_last()-1) + $a_field_event_type_index));                
				break;		
            }   
        }        
		public function add_field_from_string($a_field_str)
		{
			$local_field = t_base_field::create_field_from_string($this,$a_field_str);
			if ($local_field)
            {
				//echo "local_field->name: $local_field->name<br>";
                if (array_key_exists($local_field->name,$this->fields))
                {
                    if ($this->fields[$local_field->name]->uses_as_included_in)
                        $local_field = $this->fields[$local_field->name];
                    else    
                        throw new Exception('Error in part name '.$this->part_name.", field name $local_field->name already exist.");
                }
                else
                {
              
					if ((!isset($this->executor_field)) && ($this->is_executor_field($local_field)))
					{
						/*** SET EXECUTOR FIELD ***/
						$this->executor_field = $local_field;
					    //echo "local_field->name: $local_field->name<br>";
					}
                    $this->fields[$local_field->name] =  $local_field;
					/*** GET THE INDEX OF THE FIELD IN THE LIST OF FIELDS OF THE PARENT COMPONENT, GOT FROM FIELD CONFIGURATION ***/
                    $local_index = $local_field->get_index_in_the_parent_fields_list();
                   // echo "local_index:$local_index<br>";
                    $local_setting_index = $local_index;
                    if ($local_setting_index == -1)
                    {
                        if (count($this->fields_positions) == 0)
                        {
                            $local_index = 1;
                            
                        }
                        else
                        {
                            if ($this->first_index_always_last_position_field > -1)
                            {
                                $local_index = $this->first_index_always_last_position_field;
                            }    
                            else
                            {
                                end($this->fields_positions); 
                                $local_index = key($this->fields_positions) + 1;
                            }   
                        }
                    }  
                    else if ($local_setting_index == -2)
                    {
                        $local_index = 0;
                    }
                    else if ($local_setting_index == -3)
                    {
                        if (count($this->fields_positions) == 0)
                        {
                            $local_index = 1;
                            
                        }
                        else
                        {
                            end($this->fields_positions); 
                            $local_index = key($this->fields_positions) + 1;
                        }
                        $this->last_field_index = $local_index; 
                        if ($this->first_index_always_last_position_field == -1)
                            $this->first_index_always_last_position_field = $local_index;
                        
                    }
                    
                    
                    if (($local_index < $this->first_index_always_last_position_field) && (array_key_exists($local_index,$this->fields_positions)))
                    {
                        throw new Exception('Error in part name '.$this->part_name.", field at position $local_index already exist.");
                    }
                    else
                    {
                        if (($local_setting_index != -3) && ($this->last_field_index > -1) && ($local_index >= $local_setting_index))
                        {
                            $local_field_to_add = array();
                            $local_difference = $this->last_field_index - $this->first_index_always_last_position_field; 
                           // echo "local_index: $local_index - this->first_index_always_last_position_field: $this->first_index_always_last_position_field - this->last_field_index: $this->last_field_index <br>";
                            //print_r($this->fields_positions); echo "<br>";
                            if ($local_setting_index == -2)
							{
								if ($this->fields_positions[$local_index] != '')
								{
									// gets field after new field having -2 as parent_index
									for($local_index_always_last = $local_index; $local_index_always_last <= $this->last_field_index; $local_index_always_last++)
									{
										$local_field_to_add[] = $this->fields_positions[$local_index_always_last];
										//$local_field_to_add .= "," . $this->fields_positions[$local_index_always_last];
									}
									//print_r($local_field_to_add); echo "<br>";
									//$local_last_field_value = $this->fields_positions[$this->last_field_index];
									
									array_splice($this->fields_positions, $local_index , $this->last_field_index - $local_index);	
									print_r($this->fields_positions);					
									$i = $local_index;
									for($local_index_always_last = $local_index+1; $local_index_always_last <= $this->last_field_index; $local_index_always_last++)
									{
										$this->fields_positions[$local_index_always_last] = $local_field_to_add[$i];
										$i++;
									}		
									$this->first_index_always_last_position_field = $this->first_index_always_last_position_field + 1;
									$this->last_field_index = $this->last_field_index + 1;	
								}
								$this->fields_positions[$local_index] = $local_field->name;
								//print_r($this->fields_positions);							
							}
							else
							{
								// gets field with -3 as parent_index
								for($local_index_always_last = $this->first_index_always_last_position_field; $local_index_always_last <= $this->last_field_index; $local_index_always_last++)
								{
									$local_field_to_add[] = $this->fields_positions[$local_index_always_last];
									//$local_field_to_add .= "," . $this->fields_positions[$local_index_always_last];
								}
								//print_r($local_field_to_add); echo "<br>";
								//$local_last_field_value = $this->fields_positions[$this->last_field_index];
								//print_r($this->fields_positions);
								array_splice($this->fields_positions, -1 * ($local_difference + 1), ($local_difference + 1));
								$this->first_index_always_last_position_field = $local_index + 1;
								$this->last_field_index = $this->first_index_always_last_position_field + $local_difference;
								$i = 0;
								for($local_index_always_last = $this->first_index_always_last_position_field; $local_index_always_last <= $this->last_field_index; $local_index_always_last++)
								{
									$this->fields_positions[$local_index_always_last] = $local_field_to_add[$i];
									$i++;
								}
								$this->fields_positions[$local_index] = $local_field->name;
							}
                           
							//print_r($this->fields_positions);
                            //
                            
							//print_r($this->fields_positions);
                            //
                            
                            //
                            
                            //$this->fields_positions[$this->last_field_index] = $local_last_field_value;  
                        }
                        else
						{
                            $this->fields_positions[$local_index] = $local_field->name;  
							//echo "local_index: $local_index - local_field->name: $local_field->name<br>";
						}
                        ksort($this->fields_positions);
						//print_r($this->fields_positions);
                    }  
                }    
				
            }    
			return $local_field;	
		}        
        // C
   		public function create_tags_structure()
        {
            //echo __METHOD__."<BR>";
            $local_main_tag = $this->parent_component->main_tag;
			$this->tag_for_more_fields = $this->parent_component->tag_for_more_fields;
            
            $this->main_tag = $local_main_tag->create_and_add_child_at_bottom(t_base_tag_type::btt_div,$this->part_name);
           // echo "MAIN TAG TROVATO";
		    if (isset($this->executor_field))
			{
				$local_field_item = $this->executor_field;
				$local_field_item->initialize_main_tag();
               // $local_field_item->create_tags_structure();
               // $local_field_item->create_javascript_initialization_component();
			}
            foreach($this->fields_positions as $local_field_name)
            {
				
                $local_field_item = $this->fields[$local_field_name];
				/*if ($this->executor_field != $local_field_item)
				{*/
					$local_field_item->create_tags_structure();
					$local_field_item->create_javascript_initialization_component();
/*}*/
            }
        }		
        //F
        public function finalize_creation_part()
        {
            foreach($this->fields_positions as $local_field_name)
            {
                $local_field_item = $this->fields[$local_field_name];
                $local_field_item->finalize_creation_field();
            }
        }

		// G
		public function get_last_start_tag($a_tag_type = '')
        {
			$local_return_tag = null;
			$local_return_field = null;
			$local_field = end($this->fields_positions);
			while ($local_field != false)
			{
				$local_tag = $this->fields[$local_field]->get_start_tag();
				if (isset($local_tag) && (($a_tag_type === '') || ($a_tag_type === $local_tag->base_tag_type)))
				{	
					$local_return_tag = $local_tag;
					$local_return_field = $this->fields[$local_field];
					
					$local_field = false;
				}
				else
					$local_field = prev($this->fields_positions);
			}
			return array($local_return_field,$local_return_tag);
		}
		
        public function get_call_back_action($a_event_type)
        {
            $local_action = '';
			switch ($a_event_type) 
            {
                /*********** t_base_field::field_event_type_on_selected ***********/
                case t_base_field::field_event_type_on_selected:
                    $local_action = "t_action_set_event_part";
                break;
                /*********** t_base_field::field_event_type_on_edit ***********/
                case t_base_field::field_event_type_on_edit:
                    $local_action = "t_action_set_event_part";
                break;
                /*********** t_base_field::field_event_type_on_cancel ***********/
                case t_base_field::field_event_type_on_cancel:
                    $local_action = "t_action_set_event_part";                
                break;
                /*********** t_base_field::field_event_type_on_save ***********/
                case t_base_field::field_event_type_on_save:
                    $local_action = "t_action_set_values_into_db";
                break;  
				/*********** t_base_field::field_event_type_on_insert ***********/
                case t_base_field::field_event_type_on_insert:
                    $local_action = "t_action_set_event_part";
                break;				
				/*********** t_base_field::field_event_type_on_reload ***********/
                case t_base_field::field_event_type_on_reload:
                    $local_action = "t_action_set_event_part";
                break;                
				/*********** t_base_field::field_event_type_on_delete ***********/
                case t_base_field::field_event_type_on_delete:
                    $local_action = "t_action_set_values_into_db";                        
                break;
				/*********** t_base_field::field_event_type_on_paging ***********/
                case t_base_field::field_event_type_on_paging:
                    $local_action = "t_action_set_event_part";                
				break;		
            }  
            //echo "local_action: $local_action - a_event_type:$a_event_type<br>";
			return $local_action; 
        }
        public function get_call_back_action_name($a_event_type)
        {
            $local_action = $this->get_call_back_action($a_event_type);
			return $this->get_action_name_of_part_event($a_event_type,$local_action); 
        }
        public function get_call_back_action_hashed_name($a_event_type)
        {
			return md5($this->get_call_back_action_name($a_event_type)); 
        }        
		
        abstract public function get_field_by_step($a_step);
		public function get_field($a_name)
        {	
            if (array_key_exists($a_name,$this->fields))
            {
                //echo "FOUND<br>";
                return $this->fields[$a_name];
            }    
            else
                return null;
		}
		/*public function get_main_field()
		{
			$local_field = null;
			
			if ((($this->get_fields_position_last() - 1) != $this->get_main_field_position()) && ($this->get_main_field_position() <= count($this->fields)))
			{
				
				$local_field = $this->fields[$this->fields_positions[$this->get_main_field_position()]];
			}
			//print_r($this->fields_positions);
			return $local_field;
		}*/
		public function get_part_name()
		{
			return $this->part_name;
		}		
		public function get_action_by_index($a_index)
		{
			//echo"required_actions";print_r($this->required_actions);echo"<br>";
			return $this->required_actions[$a_index];
		}		
		public function get_action_name_of_part_event($a_event,$a_action)
		{
			$local_return = '';
            $loacl_action_description = str_replace('t_action_','',$a_action);
			switch ($a_event) 
            {
                /*********** t_base_field::field_event_type_on_selected ***********/
                case t_base_field::field_event_type_on_selected:
					$local_return = $this->part_name.'_on_selected_'.$loacl_action_description.'_action';
                break;
                /*********** t_base_field::field_event_type_on_edit ***********/
                case t_base_field::field_event_type_on_edit:
					$local_return = $this->part_name."_on_edit_".$loacl_action_description."_action";
                break;
                /*********** t_base_field::field_event_type_on_cancel ***********/
                case t_base_field::field_event_type_on_cancel:
					$local_return = $this->part_name."_on_cancel_".$loacl_action_description."_action";
                break;
                /*********** t_base_field::field_event_type_on_save ***********/
                case t_base_field::field_event_type_on_save:
					$local_return = $this->part_name."_on_save_".$loacl_action_description."_action";
				break; 
                /*********** t_base_field::field_event_type_on_insert ***********/
                case t_base_field::field_event_type_on_insert:
					$local_return = $this->part_name."_on_insert_".$loacl_action_description."_action";
                break;				
				/*********** t_base_field::field_event_type_on_reload ***********/
                case t_base_field::field_event_type_on_reload:
					$local_return = $this->part_name."_on_reload_".$loacl_action_description."_action";
                break;				
                /*********** t_base_field::field_event_type_on_delete ***********/
                case t_base_field::field_event_type_on_delete:
					$local_return = $this->part_name."_on_delete_".$loacl_action_description."_action";
                break;
				/*********** t_base_field::field_event_type_on_paging ***********/
                case t_base_field::field_event_type_on_paging:
					$local_return = $this->part_name."_on_paging_".$loacl_action_description."_action";
                break;                
            } 
			return $local_return;
			
		}
        // I
        public function import_fields_array_from_string($a_fields,
            $a_uses_as_included_in)
        {
           // echo "part name: $this->part_name - a_fields:$a_fields<br>"; 
			$this->generate_fields_array($a_fields,$a_uses_as_included_in);
        }	
		public function is_executor_field($a_fields)
        {
            $local_class_name = get_class($a_fields);
			return (($local_class_name == 't_field_do_it') || ($local_class_name == 't_field_form') || ($local_class_name == 't_field_login') || ($local_class_name == 't_field_processes_engine'));
        }		
		 
		// G
        public function get_json_db_fields_list()
        {
            return "[]";
        }        
	    // H
        public function has_parent_part()
        {
            return (($this->parent_part_name != '') && ($this->parent_part_name != 'none'));
        }
	}

	interface i_base_part {
		static function get_default_specific_parameter($a_index);
		static function get_help_specific_parameter($a_index);
	}  	
?>